home *** CD-ROM | disk | FTP | other *** search
- Path: service-2.agate.net!usenet
- From: andle@biode.com (Jeffrey C. Andle)
- Newsgroups: comp.lang.c++
- Subject: Bounds checker says this is a leak. Is it?
- Date: 15 Feb 1996 04:50:42 GMT
- Organization: Biode, Inc.
- Message-ID: <4fue32$k77@service-2.agate.net>
- NNTP-Posting-Host: biode.sdi.agate.net
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.11
-
- First, I'm running VC4.0 in NT3.51 with so much virtual ram that I
- don't see leaks that Bounds checker says are there. So, is this a leak?
- I have a valid destructor which deletes each cELEMENT in the list.
- It is called & I can trace through it. I suspect that bounds checker
- is being paranoid. I create an element using new, as shown in the routine
-
- bAddTopItem(DataIn);
-
- I added the code to initialize NULL and close out with NULL in pNew
- just to see if Bounds checker still had the same opinion. It did.
- Since the new cELEMENT is on the list and is ultimately destroyed,
- If there really is a leak, I assume it has to do with the use of
- references in the constructor... (?)
-
- Any help would be vastly appreciated. This templated code is the core
- of my data linked lists, my message processing jump table and my
- child windows lists. If there really are as many leaks as Bounds checker
- says, I would thing I'd notice it...
-
- Also, how do I reliably test for memory losses in NT?
- e-mail to andle@agate.net please.
-
-
- ************************************************************* Add Element creates an element on the list
- ************************************************************* containing the data
- // ==============================================================
- // Add element to top of list
- // Pre: DataIn
- template<class ITEM,class KEY> BOOL cLINKEDLIST<ITEM,KEY>::bAddTopItem (ITEM DataIn)
- {
- cELEMENT<ITEM>* pNew = NULL;
- BOOL bSuccess = FALSE;
-
- pNew = new cELEMENT<ITEM> (DataIn, NULL, pTop); // ***********<<<<<<<<<
- if ((BOOL) pNew)
- {
- // add the new element (splice pointers)
- if (!bEmptyList())
- {
- pTop->pSetPrev (pNew);
- }
- else
- {
- // Adding first element to empty list
- pCur = pNew;
- pBot = pNew;
- }
-
- pTop = pNew;
- bSuccess = TRUE;
- }
- // attempt to convince bounds checker that pNew is elsewhere now...
- pNew = NULL;
- return bSuccess;
- };
- // post: properly spliced new element is in the list
- // returns TRUE on success. pTop = pNew
-
-
- ************************************************************ Element constructor copies DataIn
- template<class ITEM> class cELEMENT
- {
- protected:
- cELEMENT<ITEM>* pNext;
- cELEMENT<ITEM>* pPrev;
- ITEM Item;
- public:
- //===========================================================================
- // Constructor
- //
- // Comments : This is set up to accept a multitude of arguments.
- // if a class is used in the template, copy the class.
- // If a pointer to a class is used, copy the pointer.
- // In either case, copy the pointers to next & prev.
-
- inline cELEMENT (ITEM& ItemIn, cELEMENT* pPrevIn = NULL, cELEMENT* pNextIn = NULL)
- {
- // if a class is used in the template, copy the class.
- // If a pointer to a class is used, copy the pointer.
- Item = ItemIn;
-
- // In either case, copy the pointers to next & prev.
- pPrev = pPrevIn;
- pNext = pNextIn;
- };
- // POST : an instance of element has been created &&
- //===========================================================================
-
- // other stuff:
- };
-
-